package citic.c.util;

import java.math.BigDecimal;

public enum Unit {

    ONE(UnitType.ONE, "个", "unit", new BigDecimal(1L)),

    TIME_MILLISECOND(UnitType.TIME, "豪秒", "millisecond", new BigDecimal(1L)),
    TIME_SECOND(UnitType.TIME, "秒", "second", new BigDecimal(1000L)),
    TIME_MINUTE(UnitType.TIME, "分", "second", new BigDecimal(60*1000L)),
    TIME_HOUR(UnitType.TIME, "小时", "second", new BigDecimal(60*60*1000L)),
    TIME_DAY(UnitType.TIME, "天", "second", new BigDecimal(24*60*60*1000L)),
    TIME_WEEK(UnitType.TIME, "周", "second", new BigDecimal(7*24*60*60*1000L)),

    STORAGE_B(UnitType.STORAGE_B,"B","B",new BigDecimal(1L)),
    STORAGE_KB(UnitType.STORAGE_B,"KB","KB",new BigDecimal(1024L)),
    STORAGE_MB(UnitType.STORAGE_B,"MB","MB",new BigDecimal(1024*1024L)),
    STORAGE_GB(UnitType.STORAGE_B,"GB","GB",new BigDecimal(1024*1024*1024L)),
    STORAGE_TB(UnitType.STORAGE_B,"TB","TB",new BigDecimal(1024*1024*1024*1024L)),
    STORAGE_PB(UnitType.STORAGE_B,"PB","PB",new BigDecimal(1024*1024*1024*1024*1024L)),

    STORAGE_b(UnitType.STORAGE_b,"b","b",new BigDecimal(1L)),
    STORAGE_Kb(UnitType.STORAGE_b,"Kb","Kb",new BigDecimal(1024L)),
    STORAGE_Mb(UnitType.STORAGE_b,"Mb","Mb",new BigDecimal(1024*1024L)),
    STORAGE_Gb(UnitType.STORAGE_b,"Gb","Gb",new BigDecimal(1024*1024*1024L)),
    STORAGE_Tb(UnitType.STORAGE_b,"Tb","Tb",new BigDecimal(1024*1024*1024*1024L)),
    STORAGE_Pb(UnitType.STORAGE_b,"Pb","Pb",new BigDecimal(1024*1024*1024*1024*1024L)),

    CNY_HAO(UnitType.CURRENCY_CNY,"毫","hao",new BigDecimal(1L)),
    CNY_LI(UnitType.CURRENCY_CNY,"厘","li",new BigDecimal(10L)),
    CNY_CENT(UnitType.CURRENCY_CNY,"分","cent",new BigDecimal(10*10L)),
    CNY_JIAO(UnitType.CURRENCY_CNY,"角","jiao",new BigDecimal(10*10*10L)),
    CNY_YUAN(UnitType.CURRENCY_CNY,"元","Y",new BigDecimal(10*10*10*10L)),
    CNY_WYUAN(UnitType.CURRENCY_CNY,"万元","WY",new BigDecimal(10*10*10*10*10000L)),
    CNY_YYUAN(UnitType.CURRENCY_CNY,"亿元","YY",new BigDecimal(10*10*10*10*10000*10000L)),
    ;

    private String displayName;

    private String value;

    private BigDecimal ratio;

    private UnitType unitType;

    Unit(UnitType unitType, String displayName, String value, BigDecimal ratio) {
        this.unitType = unitType;
        this.displayName = displayName;
        this.value = value;
        this.ratio = ratio;
    }

    public BigDecimal convert(BigDecimal source, Unit sourceUnit) {

        if (this.unitType.equals(sourceUnit)) {
            if (this.equals(sourceUnit)) {
                return source;
            }
            return source.divide(this.ratio).multiply(sourceUnit.getRatio());
        } else {
            return null;
        }
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public BigDecimal getRatio() {
        return ratio;
    }

    public void setRatio(BigDecimal ratio) {
        this.ratio = ratio;
    }

    public UnitType getUnitType() {
        return unitType;
    }

    public void setUnitType(UnitType unitType) {
        this.unitType = unitType;
    }


}
